<?php

namespace App\Cost;

class HourCost extends AbstractCost
{
    /**
     * @var int 每小时收费价格
     */
    public int $perHourPrice = 0;

    protected function getCost(string $startTime, string $endTime): Price
    {
        //分钟数
        $minutes = (int)((strtotime($endTime) - strtotime($startTime)) / 60);
        //整小时 数
        $hours = (int)($minutes / 60);
        //超过整小时的分钟数
        $exceedMinutes = $minutes - $hours * 60;

        $basePrice = $this->perHourPrice * $hours;
        //没有超时，直接返回
        if ($exceedMinutes <= 0)
            return new Price($basePrice);

        $exceedFee = $this->getExceedFee($exceedMinutes);
        $exceedMessage = $this->getExceedMessage();

        return new Price($basePrice, $exceedMinutes, $exceedFee, $exceedMessage);
    }

    protected function getPricePerMinutes(): float
    {
        return $this->perHourPrice / 60;
    }

    public function getPerMinutesPrice(): float|null
    {
        return $this->getPricePerMinutes() / 100;
    }
}
